#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h> 
#include <stdlib.h>
#include <assert.h>
#include "app_platform/cntl_info.h"
#include "gismapgatewayao.h"


using namespace erp::gis::ao;

CPP_SELF_DEFINE_START
/**
*  请在这里增加自定义的成员变量和函数及其他内容，否则无法合并代码
**/

#include "gismap_handler.h"
#include "gismap_globalconfig.h"
#include "gismapgatewayao_itil_def.h"

#include "libc2c/c2c_errno_define.h"
#include "c2cent/library/log/CWTimeElf3.h"

#include "erp/gis/comm/erp_gis_define.h"
#include "erp/gis/comm/erp_gis_func_define.h"
#include "erp/comm/erp_macro_define.h"
#include "erp/comm/erp_errno_define.h"

using namespace std;
using namespace c2cent::library::wwlog;
using namespace c2cent::library::wtimeelf;

using namespace erp::comm;
using namespace erp::gis::ao;
using namespace erp::gis::comm;


#define DEFAUL_LOG_MODULE "ao_gis_mapgateway"
#define C2C_WW_LOG_FUNC_START() do{\
	C2C_WW_SIM_LOG_PL_HEAD();\
	C2C_WW_LOG("====%s Invoked. OperatorUin: %u MachineKey:%s Source: %s SceneId:%u ", __FUNCTION__, \
               rCntlInfo.getOperatorUin(), strMachineKey.c_str(), strSource.c_str(), dwSceneId);\
}while(0)

#define C2C_WW_LOG_FUNC_END() do{\
	C2C_WW_LOG("====%s Finish.  OperatorUin: %u Source: %s", __FUNCTION__, rCntlInfo.getOperatorUin(), strSource.c_str());\
}while(0)

#define GetAndSetMapConfig(config)do{\
	uint32_t dwTimeout       = 0; \
	uint32_t dwNeedCheck     = 1; \
	uint32_t dwProxyPort     = 0;  \
	std::string strProxyList = "";  \
	std::string strUrl       = "";  \
	GetUintConfig2(config, Timeout);\
	GetUintConfig2(config, NeedCheck);\
	GetUintConfig2(config, ProxyPort);\
	GetStringConfig2(config, ProxyList);\
	GetStringConfig2(config, Url);\
	CGisMapGlobalConfig::Set##config##Config(dwNeedCheck > 0, dwTimeout, strUrl, strProxyList);\
}while(0)


///////////////////////////////////////////////////
///////////////////////////////////////////////////

std::string CGisMapGatewayAo::m_strLogModule;
uint32_t CGisMapGatewayAo::m_dwReqSlowValue;

uint32_t CGisMapGatewayAo::CheckCoordinateQueryPo(
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				std::string& strErrMsg)
{
	if (oCoordinatesQueryPo.GetDestAddrDetail().empty())
	{
		strErrMsg = "query destination detail can't be empty";
		return ERR_APP_PARAM_INVALID;
	}

	if (oCoordinatesQueryPo.GetDestAddrCity().empty())
	{
		strErrMsg = "query destination text can't be empty";
		return ERR_APP_PARAM_INVALID;
	}

	return 0;
}

uint32_t CGisMapGatewayAo::GetCoordinateFromGisMap(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				uint32_t dwApiType,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve)
{
	DUMP_XXO_DEBUG_LOG(oCoordinatesQueryPo);

	uint32_t dwRet = CheckCoordinateQueryPo(oCoordinatesQueryPo, strErrMsg);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, "CheckCoordinateQueryPo Failed. ErrMsg:%s", strErrMsg.c_str());
		return dwRet;
	}

	SGisMapParam stGisMapParam;
	stGisMapParam.dwApiType  = dwApiType;
	stGisMapParam.strCity    = oCoordinatesQueryPo.GetDestAddrCity();
	stGisMapParam.strAddress = oCoordinatesQueryPo.GetDestAddrDetail();
	
	dwRet = CGIS_MAP_HANDLER->GetCoordinates(stGisMapParam, vecCoordinatesPo);
	if (ERR_ERP_GIS_GATEWAY_REQUEST_API_FAILED == dwRet ||
		ERR_ERP_GIS_GATEWAY_REQUEST_LIMITATION == dwRet)
	{
		strErrMsg = CGIS_MAP_HANDLER->GetLastErrMsg();
		C2C_WW_LOG_FERR(dwRet, 
			"CGIS_MAP_HANDLER->GetCoordinates Failed. ApiTpye:%u FullAddress:%s ErrMsg:%s",
			dwApiType, oCoordinatesQueryPo.GetDestAddrDetail().c_str(), strErrMsg.c_str());

		return dwRet;
	}
	else if (0 != dwRet)
	{
		C2C_WW_LOG("CGIS_MAP_HANDLER->GetCoordinates Failed. Ret:%u ApiType:%u FullArress:%s ErrMsg:%s",
			dwRet, dwApiType, oCoordinatesQueryPo.GetDestAddrDetail().c_str(), strErrMsg.c_str());
		dwRet = 0;
	}
	else
	{
		C2C_WW_LOG("oGisMapHandler.GetCoordinates OK. ApiType:%u Size:%u", 
			dwApiType, (uint32_t)vecCoordinatesPo.size());
	}

	return 0;
}





CPP_SELF_DEFINE_END

/**
 *构建函数
 */
CGisMapGatewayAo::CGisMapGatewayAo(enum DeployMethod method)
{

}

/**
 *析构函数
 */
CGisMapGatewayAo::~CGisMapGatewayAo()
{

}


/**
 *每一次服务请求时，container都会调用此方法来清空数据
 */
void  CGisMapGatewayAo::Reset()
{

}


int  CGisMapGatewayAo::Initialize(IUserDefineCntl* pCntl)
{
	std::cout<<"File:"<<__FILE__<<"Complie Date: "<<__DATE__<<" "<<__TIME__<<std::endl;

	int32_t  iRetcode = 0;
	uint32_t dwCanLogRemote  = 0;
	uint32_t dwLogSwitch = WLOG_OPEN | WLOG_KEY_OPEN | WLOG_ERR_OPEN | WLOG_DEG_OPEN;
	std::string strLogModule = DEFAUL_LOG_MODULE;

	GetUintConfig(LogSwitch);
	GetStringConfig(LogModule);
	iRetcode = C2C_WWLOG->QuickInitForAPP2(strLogModule.c_str(), 
				C2CWW_LOG_APP_FILE_PATH, dwCanLogRemote, dwLogSwitch);
	if (iRetcode != 0)
	{
		std::cout<<"LogInit Failed Ret:"<<iRetcode<<" Name:"<< DEFAUL_LOG_MODULE 
			     <<"RemoteLevel:"<<dwCanLogRemote<<std::endl;
		return -1;
	}
	std::cout<<"C2C_WWLOG->QuickInitForAPP2 OK!"<<std::endl;
	C2C_WW_LOG("C2C_WWLOG->QuickInitForAPP2 OK!");

	m_strLogModule = strLogModule;

	uint32_t dwReqSlowValue = 30;
	uint32_t dwSwitchProxyThreshold = 100;
	GetUintConfig(ReqSlowValue);
	GetUintConfig(SwitchProxyThreshold);
	m_dwReqSlowValue = dwReqSlowValue;

	CGisMapGlobalConfig::SetSwitchProxyThreshold(dwSwitchProxyThreshold);
	
	GetAndSetMapConfig(Soso);
	GetAndSetMapConfig(Soso2);
	GetAndSetMapConfig(Baidu);
	GetAndSetMapConfig(Google);
	GetAndSetMapConfig(Aliyun);
	GetAndSetMapConfig(Gaode);

	CGIS_MAP_HANDLER->RegisterMapRequest<CSoSoRequest>(E_GISMAP_API_SOSO);
	CGIS_MAP_HANDLER->RegisterMapRequest<CSoSo2Request>(E_GISMAP_API_SOSO2);
	CGIS_MAP_HANDLER->RegisterMapRequest<CBaiduRequest>(E_GISMAP_API_BAIDU);
	CGIS_MAP_HANDLER->RegisterMapRequest<CGoogleRequest>(E_GISMAP_API_GOOGLE);
	CGIS_MAP_HANDLER->RegisterMapRequest<CAliyunRequest>(E_GISMAP_API_ALIYUN);
	CGIS_MAP_HANDLER->RegisterMapRequest<CGaodeRequest>(E_GISMAP_API_GAODE);

	std::cout << "Initialize Success" << std::endl;
	C2C_WW_LOG("Initialize Success");
	return 0;
}


/**
 *
 * 获取soso地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetSosoCoordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetSosoCoordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetSosoCoordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetSosoCoordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetSosoCoordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_SOSO,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}

/**
 *
 * 获取soso2地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetSoso2Coordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetSoso2Coordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetSoso2Coordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetSoso2Coordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetSoso2Coordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_SOSO2,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}

/**
 *
 * 获取baidu地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetBaiduCoordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetBaiduCoordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetBaiduCoordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetBaiduCoordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetBaiduCoordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_BAIDU,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}

/**
 *
 * 获取google地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetGoogleCoordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetGoogleCoordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetGoogleCoordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetGoogleCoordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetGoogleCoordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_GOOGLE,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}

/**
 *
 * 获取阿里云地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetAliyunCoordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetAliyunCoordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetAliyunCoordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetAliyunCoordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetAliyunCoordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_ALIYUN,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}

/**
 *
 * 获取高德地图经纬度 
 *
 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值  [in]				
 *@param String source: 调用来源文件名称，必填  [in]				
 *@param uint32_t sceneId: 场景id，必填（目前填0即可）  [in]				
 *@param CoordinatesQueryPo coordinatesQueryPo: 经纬度查询PO  [in]				
 *@param String inReserve: 请求保留字段  [in]				
 *@param Vector coordinatesPo: 经纬度PO列表 	[out]	
 *@param String errMsg: 错误信息 	[out]	
 *@param String outReserve: 请求保留字段 	[out]	
 *
 *@return  uint32_t : 0(成功) 其它失败
 *
 */
uint32_t CGisMapGatewayAo::GetGaodeCoordinates(
				const CCntlInfo& rCntlInfo,
				const std::string& strMachineKey,
				const std::string& strSource,
				uint32_t dwSceneId,
				const erp::gis::po::CCoordinatesQueryPo& oCoordinatesQueryPo,
				const std::string& strInReserve,
				std::vector<erp::gis::po::CCoordinatesPo >& vecCoordinatesPo,
				std::string& strErrMsg,
				std::string& strOutReserve
	)
{
	C2C_WW_LOG_FUNC_START();
	uint32_t dwRet = 0;
	CItilGroup oCItilGroup(
			E_ITIL_GISMAPGATEWAYAO_GetGaodeCoordinates_REQ,
			E_ITIL_GISMAPGATEWAYAO_GetGaodeCoordinates_ERR,
			E_ITIL_GISMAPGATEWAYAO_GetGaodeCoordinates_RSP,
			E_ITIL_GISMAPGATEWAYAO_GetGaodeCoordinates_SLOW,
			m_dwReqSlowValue);
	C2C_TIME_ELF_ITIL oWTimeElf(C2C_WWLOG, __FUNCTION__, (int*) &dwRet, &oCItilGroup);

	if (strMachineKey.empty() || strSource.empty())
	{
		dwRet = ERR_APP_PARAM_INVALID;
		C2C_WW_LOG_FERR(dwRet, "MachineKey or Source Empty");
		return dwRet;
	}

	dwRet = GetCoordinateFromGisMap(
					rCntlInfo, 
					strMachineKey, 
					strSource,
					dwSceneId,
					E_GISMAP_API_GAODE,
					oCoordinatesQueryPo,
					strInReserve,
					vecCoordinatesPo,
					strErrMsg,
					strOutReserve);
	if (0 != dwRet)
	{
		C2C_WW_LOG_FERR(dwRet, 
			"GetCoordinateFromGisMap Failed. Province:%s City:%s District:%s Text:%s ErrMsg:%s",
			oCoordinatesQueryPo.GetDestAddrProvince().c_str(),
			oCoordinatesQueryPo.GetDestAddrCity().c_str(),
			oCoordinatesQueryPo.GetDestAddrDistrict().c_str(),
			oCoordinatesQueryPo.GetDestAddrDetail().c_str(),
			strErrMsg.c_str());
		return dwRet;
			
	}

	if (C2C_WWLOG->IsDebugLogOpen())
	{
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iter = vecCoordinatesPo.begin();
		std::vector<erp::gis::po::CCoordinatesPo>::const_iterator iterEnd = vecCoordinatesPo.end();
		for (; iter != iterEnd; iter++)
		{
			C2C_WW_LOG_DEBUG("(x:%s y:%s)", iter->GetXPoint().c_str(), iter->GetYPoint().c_str());
		}
	}

	C2C_WW_LOG_FUNC_END();	
	return 0;
}
